# backend/app/api/api_user.py

from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from app.db.db_handler import get_db
from app.db.db_models import User
from app.auth.jwt import get_current_active_user

from app.api.api_model import SuccessResponse

router = APIRouter(
    prefix="/users",
    tags=["Users"],
)

db_dict = dict()

@router.get("/me", summary="获取当前用户信息")
async def read_users_me(current_user: User = Depends(get_current_active_user)):
    """获取当前用户的详细信息"""
    return SuccessResponse(data=current_user)

@router.put("/me", summary="更新当前用户信息")
async def update_users_me(email: str, full_name: str, current_user: User = Depends(get_current_active_user)):
    """更新当前用户的详细信息"""
    db_user: User = db_dict["User"]
    db_user.update_user(current_user.id, email, full_name)
    current_user = get_current_active_user()
    return SuccessResponse(data=current_user)